package action;

import annotation.Action;
import annotation.Controller;
import annotation.Result;
import entity.User;
import enu.ResultType;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@Controller
@Action(path = "/user")
public class UserAction {
    @Action(path = "/showLogin",forward="/WEB-INF/login.jsp")
    public void showLogin(){}

    @Action(path = "/login",results = {
            @Result(name = "success",path = "/showSuccess",type = ResultType.REDIRECT),
            @Result(name = "fail",path = "/WEB-INF/login.jsp",type = ResultType.FORWARD)
    })
    public String login(HttpServletRequest request, HttpServletResponse response){
        System.out.println("UserAction.login()");

        String username = request.getParameter("username");
        String password = request.getParameter("password");

        if("abc".equals(username)&&"123".equals(password)){
            System.out.println("用户登录...");
            return "success";
        }

        request.setAttribute("message","用户名或密码错误");
        return "fail";
    }

    public String f1(){
        return null;
    }


    @Action(path = "/regist")
    public String regist(HttpServletRequest request, HttpServletResponse response){
        return null;
    }


    @Action(path = "/findUser",results = @Result(type = ResultType.JSON))
    public User findUser(HttpServletRequest request,HttpServletResponse response){
        User user=new User();
        user.setId(1);
        user.setUsername("abc");
        user.setPassword("123");
        user.setPhone("12345678");
        return user;
    }


























}
